import { ResponseCode } from './response.js';

/**
 * 基础异常类
 */
export class BaseException extends Error {
  constructor(
    public code: ResponseCode,
    public message: string,
    public data?: unknown
  ) {
    super(message);
    this.name = this.constructor.name;
  }
}

/**
 * 参数异常
 */
export class IllegalArgumentsException extends BaseException {
  constructor(message: string, data?: unknown) {
    super(ResponseCode.ILLEGAL_ARGUMENTS, message, data);
  }
}

/**
 * 验证异常
 */
export class ValidationException extends BaseException {
  constructor(message: string, data?: unknown) {
    super(ResponseCode.VALIDATION_ERROR, message, data);
  }
}

/**
 * 未授权异常
 */
export class UnauthorizedException extends BaseException {
  constructor(message: string = '未授权访问', data?: unknown) {
    super(ResponseCode.UNAUTHORIZED, message, data);
  }
}

/**
 * 禁止访问异常
 */
export class ForbiddenException extends BaseException {
  constructor(message: string = '禁止访问', data?: unknown) {
    super(ResponseCode.FORBIDDEN, message, data);
  }
}

/**
 * 资源未找到异常
 */
export class NotFoundException extends BaseException {
  constructor(message: string = '资源未找到', data?: unknown) {
    super(ResponseCode.NOT_FOUND, message, data);
  }
}

/**
 * 业务异常
 */
export class BusinessException extends BaseException {
  constructor(message: string, data?: unknown) {
    super(ResponseCode.FAIL, message, data);
  }
}

/**
 * 服务器异常
 */
export class ServerException extends BaseException {
  constructor(message: string = '服务器内部错误', data?: unknown) {
    super(ResponseCode.INTERNAL_ERROR, message, data);
  }
}
